package com.kun.demo04_synchronize.probelm;

import org.junit.Test;

import java.util.List;

public class NotSafeCase3_list {

    List<String> list = new java.util.ArrayList<>();

    class TestList implements Runnable {

        @Override
        public void run() {
            list.add(Thread.currentThread().currentThread().getName());
        }
    }


    @Test
    public void test() throws InterruptedException {
        TestList testList = new TestList();

        for (int i = 0; i < 10000; i++) {
            new Thread(testList, "thread-" + i).start();
        }
        Thread.sleep(2000);
        System.out.println("list预想长度："+10000);
        System.out.println("list实际长度："+list.size());

    }
}
